<template>
	<!-- :style="'padding-bottom:'+bottomPadding+'rpx'" -->
	<view class="tabbar">
		<view class="tabs" :style="'background-color:'+ktabbarBgColor">
			<template v-for="(item, index) in (ktheme == 'purple' ? list : list1) ">
				<view class="item" :key=" index" @click="switchTab(index)">
					<image :src="elIconPath(index)" mode="scaleToFit"></image>
					<view class="label" :style="'color:'+knavTitleColor">
					{{item.label}}
					</view>
				</view>
			</template>
		</view>
		<view class="fixedbox"></view>
	</view>
</template>

<script>
	export default {
		props: {
			// 通过v-model绑定current值
			value: {
				type: [String, Number],
				default: 0
			}
		},
		data() {
			return {
				bottomPadding:0,
				list: [
					{
						iconPath: '/static/tabbar/home.png',
						selectIconPath: '/static/tabbar/home_select.png',
						pagePath: '/pages/index/index',
						label: '首页'
					},
					{
						iconPath: '/static/tabbar/market.png',
						selectIconPath: '/static/tabbar/market_select.png',
						pagePath: '/pages/mart/mart',
						label: '市场'
					},
					{
						iconPath: '/static/tabbar/notice.png',
						selectIconPath: '/static/tabbar/notice_select.png',
						pagePath: '/pages/notice/notice',
						label: '社区'
					},
					{
						iconPath: '/static/tabbar/user.png',
						selectIconPath: '/static/tabbar/user_select.png',
						pagePath: '/pages/user/user',
						label: '我的'
					}
				],
				
				list1: [
					{
						iconPath: '/static/tabbar/home_normal1.png',
						selectIconPath: '/static/tabbar/home_select1.png',
						pagePath: '/pages/index/index',
						label: '首页'
					},
					{
						iconPath: '/static/tabbar/market_normal1.png',
						selectIconPath: '/static/tabbar/market_select1.png',
						pagePath: '/pages/mart/mart',
						label: '市场'
					},
					{
						iconPath: '/static/tabbar/notice_normal1.png',
						selectIconPath: '/static/tabbar/notice_select1.png',
						pagePath: '/pages/notice/notice',
						label: '社区'
					},
					{
						iconPath: '/static/tabbar/user_normal1.png',
						selectIconPath: '/static/tabbar/user_select1.png',
						pagePath: '/pages/user/user',
						label: '我的'
					}
				],
				pageUrl: '', // 当前页面URL
			}
		},
		created() {
			uni.hideTabBar();
			// 获取引入了u-tabbar页面的路由地址，该地址没有路径前面的"/"
			let pages = getCurrentPages();
			// 页面栈中的最后一个即为项为当前页面，route属性为页面路径
			this.pageUrl = pages[pages.length - 1].route;
			// 安卓｜iOS 底部安全距离
			// uni.getSystemInfo({
			// 	success: res => {
			// 		this.bottomPadding = (res.screenHeight - res.safeArea.bottom) * 2 || 30
			// 		console.log('安全距离'+this.bottomPadding)
			// 	}
			// })
		},
		computed: {
			elIconPath() {
				return (index) => {
					let pagePath = this.exchangeList()[index].pagePath;
					if(pagePath == this.pageUrl || pagePath == '/' + this.pageUrl) {
						return this.exchangeList()[index].selectIconPath;
					} else {
						return this.exchangeList()[index].iconPath;
					}
				}
			},
		},
		methods: {
			exchangeList(){
				if(this.ktheme == 'purple'){
					return this.list
				}else{
					return this.list1
				}
			},
			// 切换tab
			switchTab(index) {
				if(this.exchangeList()[index].pagePath) {
					uni.switchTab({
						url: this.exchangeList()[index].pagePath
					});
				}
			},
		}
	}
</script>

<style scoped lang="scss">
	.tabbar {
		.tabs {
			width: 100%;
			height: 160rpx;
			// background-color: rgba(255, 255, 255,1);// .9
			padding: 0 60rpx;
			box-sizing: border-box;
			display: flex;
			align-items: center;
			justify-content: space-between;
			position: fixed;
			left: 0;
			bottom: 0;
			z-index: 99999;
			.item {
				text-align: center;
				image {	
					width: 44rpx;
					height: 44rpx;
					display: block;
					margin: 0 auto 12rpx;
				}
				.label {
					font-size: 28rpx;
					color: #333;
					font-weight: 400;
				}
			}
			// & > view:nth-child(1) {
			// 	image {
			// 		width: 37.16rpx;
			// 	}
			// }
			// & > view:nth-child(2) {
			// 	image {
			// 		width: 41.62rpx;
			// 		height: 35.82rpx;
			// 		margin-bottom: 13rpx;
			// 	}
			// }
			// & > view:nth-child(3) {
			// 	image {
			// 		width: 36.05rpx;
			// 	}
			// }
			// & > view:nth-child(4) {
			// 	image {
			// 		width: 38.59rpx;
			// 	}
			// }
		}
		.fixedbox {
			width: 100%;
			height: 160rpx;
		}
	}
</style>
